<template>
  <div class="leftBatWrapper">
    <img ref="userActvator" :src="authStore.userInfo.avatar" class="actvator" @click="showUserHanlder" />
    <div class="centerMenu">
      <div class="menu" @click="pushPage('/home/comments')">
        <MessageOutlined v-if="!activeMenu('comments')" class="routerIcon" />
        <MessageFilled v-if="activeMenu('comments')" class="routerIcon active" />
        <div class="count">1</div>
      </div>
      <div class="menu" @click="pushPage('/home/users')">
        <i class="fa routerIcon fa-user-o" v-if="!activeMenu('users')"></i>
        <i class="fa routerIcon fa-user active" v-if="activeMenu('users')" style="font-size: 23px;"></i>
      </div>
      <div class="menu" @click="pushPage('/home/star')">
        <CodeSandboxOutlined class="routerIcon" :class="{ active: activeMenu('star') }" />
      </div>
      <div class="menu">
        <FileSearchOutlined class="routerIcon" @click="tips"/>
      </div>
      <div class="menu" @click="openMoments">
        <CompassOutlined class="routerIcon" />
      </div>
      <!-- <div class="menu">
        <Icon @click="tips">
          <template #component>
            <img src="@/assets/images/ai.svg" />
          </template>
        </Icon>
      </div> -->
    </div>
    <div class="bottomMenu">
      <MenuOutlined @click="showMenus=!showMenus"/>
    </div>
    <teleport to="#overlayTarget" v-if="showUserInfo">
      <UserInfo :pos="pos"/>
    </teleport>
    <teleport to="#overlayTarget" v-if="showMenus">
      <div class="menusWrapper">
        <ul class="menus">
          <li>系统设置</li>
          <li @click="logout">退出登录</li>
        </ul>
      </div>
    </teleport>
  </div>
</template>
<script setup lang="ts">
import { showMomentsWin, loginOut } from '@/utils/Electron'
import { ref, reactive, onMounted, onUnmounted } from 'vue'
import useAuthStore from '@/stores/authStore'
import useChatStore from '@/stores/chatStore'
import UserInfo from './UserInfo.vue'
import Icon, {
  MessageFilled,
  MessageOutlined,
  UserOutlined,
  CodeSandboxOutlined,
  CodeSandboxCircleFilled,
  FileSearchOutlined,
  CompassOutlined,
  MenuOutlined
} from '@ant-design/icons-vue'
import { message } from 'ant-design-vue'
import { RouterLink, useRoute } from 'vue-router'
import router from '@/router'
import PubSub from 'pubsub-js'
const route = useRoute()
const showUserInfo = ref<boolean>(false)
const userActvator = ref(null)
const showMenus = ref<boolean>(false)
const chatStore = useChatStore()
const authStore = useAuthStore()

const pos = reactive({
  top: 0,
  left: 0
})
// 显示当前用户信息
const showUserHanlder = (e: MouseEvent) => {
  e.stopPropagation()
  pos.left = e.clientX
  pos.top = e.clientY
  showUserInfo.value = true
}
const activeMenu = (name = '') => {
  return route.name === name
}
const pushPage = (path: '') => {
  router.push(path)
}
const openMoments = () => {
  showMomentsWin()
}
const getNoReadMessage = () => {}
const tips = () => {
  message.info('此功能暂未开发')
}
// 退出登录
const logout = () => {
  chatStore.resetStore()
  // clearLocalStrage()
  loginOut()
}
onMounted(()=> {
  console.log(authStore)
  PubSub.subscribe('closeWindowModal', ()=> {
    showUserInfo.value = false
  })
})
onUnmounted(()=> {
  PubSub.unsubscribe('closeWindowModal')
})
</script>
<style lang="less" scoped>
.leftBatWrapper {
  width: 55px;
  background-color: #211f1f;
  display: flex;
  flex-direction: column;
  align-items: center;
  .actvator {
    width: 36px;
    height: 36px;
    border-radius: 2px;
    margin-top: 35px;
  }
  .centerMenu {
    display: flex;
    flex-direction: column;
    font-size: 20px;
    color: hsl(0deg 0% 51%);
    gap: 22px;
    width: 100%;
    margin-top: 22px;
    .menu {
      width: 100%;
      text-align: center;
      position: relative;
      outline: none;
      &:hover {
        color: rgb(190, 190, 190);
      }
      img {
        width: 31px;
        height: 31px;
      }
      .count {
        background-color: #f73838;
        border-radius: 18px;
        position: absolute;
        right: 15%;
        top: 0;
        font-size: 11px;
        color: white;
        padding: 2px 5px;
        line-height: 1.1;
      }
    }
    .routerIcon {
      outline: none;
    }
    .active {
      color: #07c160;
    }
  }
  .bottomMenu {
    display: flex;
    flex-direction: column;
    margin-top: 30px;
    font-size: 20px;
    color: hsl(0, 0%, 51%);
    gap: 27px;
    position: absolute;
    bottom: 2%;
  }
}
.menusWrapper {
  position: absolute;
  bottom: 5px;
  left: 57px;
  background-color: #211f1f;
  border-radius: 5px;
  width: 100px;
  padding: 10px 20px;
  text-align: center;
  ul {
    list-style: none;
    color: white;
    padding: 0;
    margin: 0;
    li {
      border-bottom: 1px solid #313131;
      padding: 10px 10px;
      font-size: 15px;
      color: #cecece;
      cursor: pointer;
      &:last-child {
        border: none;
      }
    }
  }
}
</style>
